﻿#include "GetColumnInfo.h"

GetColumnInfo::GetColumnInfo(void)
{
	m_columnNum = 0;
	m_RecordLength = 0;
	m_pColumnInfo = NULL;
	m_pDataOffset = NULL;
}

GetColumnInfo::~GetColumnInfo(void)
{
	ReleasColumnInfo();
}

void GetColumnInfo::ReleasColumnInfo()
{
	if (m_pColumnInfo)
	{
		delete [](char*)m_pColumnInfo;
		m_pColumnInfo = NULL;
	}
	if (m_pDataOffset)
	{
		delete [](int*)m_pDataOffset;
		m_pDataOffset = NULL;
	}
	if (m_columnNum>0)
	{
		m_columnNum = 0;
	}
	if (m_RecordLength>0)
	{
		m_RecordLength = 0;
	}
}

int GetColumnInfo::InitColumnInfo(int Apptype, int TableId, int PtlParamType)
{
	ReleasColumnInfo();

	int ret = g_DbCfgFunObj.GetCurTableColumnInfo(Apptype, TableId, (char*&)m_pColumnInfo, m_pDataOffset, m_columnNum, m_RecordLength, PtlParamType);
	if (ret <= 0 || !m_pColumnInfo || !m_pDataOffset || m_RecordLength<=0 || m_columnNum<=0)
	{
		return -1;
	}
	return 1;
}
bool GetColumnInfo::IsSafe()
{
	if (!m_pColumnInfo || !m_pDataOffset || m_RecordLength<=0 || m_columnNum<=0)
	{
		return false;
	}else
	{
		return true;
	}
}